#include "precompile.h"
#include "base_weak_ptr.h"


_SSL_BEGIN
_SSBASEL_BEGIN

weak_reference::e_flag::e_flag()
: is_valid_(true)
{

}

void weak_reference::e_flag::invalidate()
{
	is_valid_ = false;
}

bool weak_reference::e_flag::is_valid() const
{
	return is_valid_;
}

weak_reference::e_flag::~e_flag()
{

}

weak_reference::weak_reference()
{

}

weak_reference::weak_reference(const e_flag* flag)
	: flag_(flag)
{

}

weak_reference::~weak_reference()
{

}

bool weak_reference::is_valid() const
{
	return flag_.get() && flag_->is_valid();
}

weak_reference_owner::weak_reference_owner()
{

}

weak_reference_owner::~weak_reference_owner()
{
	invalidate();
}

weak_reference weak_reference_owner::get_ref() const
{
	// If we hold the last reference to the Flag then create a new one.
	if(!has_refs())
		flag_.assign_no_ref(new weak_reference::e_flag());

	return weak_reference(flag_.get());
}

void weak_reference_owner::invalidate() {
	if (flag_.get()) {
		flag_->invalidate();
		flag_ = NULL;
	}
}

weakPtr_base::weakPtr_base()
{

}

weakPtr_base::~weakPtr_base()
{

}

weakPtr_base::weakPtr_base(const weak_reference& ref)
	: ref_(ref)
{

}


_SSBASEL_END
_SSL_END
